package com.witdata.controller.course;
import java.util.List;

import org.springframework.web.bind.annotation.*;

import com.witdata.common.domain.Result;
import com.witdata.common.domain.Status;
import com.witdata.common.domain.vo.UserVo;
import com.witdata.common.exception.GlobalException;
import com.witdata.common.service.course.CourseUsersService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;


@RestController
@RequiredArgsConstructor
@RequestMapping("/classroom/users")
@Tag(name = "课程用户管理")
public class CourseUsersController {

    private final CourseUsersService courseUsersService;

    @GetMapping("/add/{courseId}/{userId}/{type}")
    public Result<String> addUser(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId, @PathVariable("type") Integer type) {
        Boolean exists = courseUsersService.addUser(courseId, userId, type);
        if (!exists) throw new GlobalException(Status.ADD_TEACHER_FAILED);
        return Result.ok(Status.SUCCESS);
    }

    @GetMapping("/remove/{courseId}/{userId}")
    public Result<String> removeUser(@PathVariable("courseId") Long courseId, @PathVariable("userId") Long userId) {
        Boolean exists = courseUsersService.removeUser(courseId, userId);
        if (!exists) throw new GlobalException(Status.REMOVE_TEACHER_FAILED);
        return Result.ok(Status.SUCCESS);
    }

    @GetMapping("/list/{courseId}/{type}")
    public Result<List<UserVo>> getCourseUserList(@PathVariable("courseId") Long courseId, @PathVariable("type") Integer type) {
        return Result.ok(Status.SUCCESS, courseUsersService.getCourseUserList(courseId, type));
    }
}
